package com.feicheng.controller.admin;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.persistence.entity.Asetting;
import com.feicheng.persistence.service.IAsettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhengyi
 * @since 2025-04-28
 */
@RestController
@RequestMapping("/admin/settings")
public class SettingController {

    @Autowired
    IAsettingService iAsettingService;

    @GetMapping("/xtsz")
    public ResultInfo getShxxInfo() {
        JSONObject param = new JSONObject();
        Asetting xtsz = iAsettingService.getById("1");
        param.put("xtsz", xtsz);
        return ResultInfo.success(param);
    }

    @GetMapping("/sm")
    public ResultInfo getSmInfo() {
        JSONObject param = new JSONObject();
        QueryWrapper<Asetting> qw = new QueryWrapper<>();
        qw.select("setid", "mztk", "kdzn", "kdsq");
        qw.eq("setid", "1");

        Asetting xtsz = iAsettingService.getOne(qw);
        param.put("xtsz", xtsz);
        return ResultInfo.success(param);
    }

    @GetMapping("/tjlx")
    public ResultInfo getTjlxInfo() {
        JSONObject param = new JSONObject();
        QueryWrapper<Asetting> qw = new QueryWrapper<>();
        qw.select("setid", "tjlx");
        qw.eq("setid", "1");

        Asetting xtsz = iAsettingService.getOne(qw);
        param.put("xtsz", xtsz);
        return ResultInfo.success(param);
    }

    @PostMapping("/xtsz/info")
    public ResultInfo saveShxx(@RequestBody Asetting asetting) {
        JSONObject param = new JSONObject();
        QueryWrapper qw = new QueryWrapper();
        qw.eq("setid", asetting.getSetid());
        boolean update = iAsettingService.update(asetting, qw);
        param.put("saveMsg", update);
        return ResultInfo.success(param);
    }
}